import { db, TABLE } from '#utils/dbconf.js'
import { resSuccess } from '#utils/res.js'
import { DamnError } from '#utils/error.js'
import TokenTools from '#utils/token.js'
import mockJS from 'mockjs'

const { Random } = mockJS

async function get({ params: { id } }, res) {
  const row = await db.table(TABLE.USER).where({ id }).find()
  return res.send(resSuccess(row))
}

async function getList({ query }, res) {
  const { page = 1, size = 15, nickName = false } = query || {}
  const where = {}
  if (nickName) where.nickName = ['LIKE', `%${nickName}%`]
  const { data: list, count: total } = await db
    .table(TABLE.USER)
    .where(where)
    .order('id DESC')
    .page(page, size)
    .countSelect()
  return res.send(resSuccess({ list, total }))
}

export default { get, getList }
